<template>
    <view class="page container">
      <u-form
        :model="basicForm"
        :rules="rules"
        labelPosition="top"
        ref="form"
        labelWidth="auto"
        :labelStyle="{
            fontSize: '14px',
            color: '#B2B2B2',
            lineHight: '20px'
        }"
      >
        <view class="basic-style">
          <u-form-item label="名称" prop="gsdaId" required>
            <h-select-company-input-popup
              style="width: 100%"
              v-model="basicForm.gsdaId"
              commercialType="1"
              placeholder="请选择公司"
              border="surround"
                          suffixIcon="arrow-down-fill"
                          auditStatus="2"
                          :suffixIconStyle="{ color: '#B2B2B2' }"
            ></h-select-company-input-popup>
          </u-form-item>
                  <!-- <template>
                      <u-form-item label="是否为付款单位" prop="isFk" required>
                        <h-select-input-tag
                          name="isFk"
                          class="w-100"
                          v-model="basicForm.isFk"
                          objectField="basicForm.isFk"
                              suffixIcon="arrow-down-fill"
                              :suffixIconStyle="{ color: '#B2B2B2' }"
                          placeholder="请选择是否为付款单位"
                          border="surround"
                          dictName="yes_no"
                        ></h-select-input-tag>
                      </u-form-item>
                  </template> -->

                  <template v-if="signSealWay == 'online'">
                      <u-form-item label="我方经办人" prop="psnName" required>
                          <u--input v-model="basicForm.psnName" placeholder="请输入我方经办人"></u--input>
                      </u-form-item>
                      <u-form-item label="联系方式" prop="psnMobile" required>
                          <u--input v-model="basicForm.psnMobile" placeholder="请输入联系方式"></u--input>
                      </u-form-item>
                  </template>
        </view>
  
        <view class="space-x-1 mt-1" style="display: flex">
          <u-button type="primary" text="保存" :loading="loading" @click="onSubmit"></u-button>
          <u-button type="primary" text="关闭" :loading="loading" @click="onClose"></u-button>
        </view>
      </u-form>
    </view>
  </template>
  
  <script>
  export default {
    name: 'TrusteeFormInfoB',
    props: {
      teamId: {
        type: [String, Number],
        default: '',
        required: false
      },
      companyId: {
        type: [String, Number],
        default: '',
        required: false
      },
          // 用印类型 电子签章 - 实体用印
          signSealWay: {
              type: [String, Number],
              default: '',
              required: false
          },
      // 表单禁用
      disabled: {
        type: Boolean,
        default: false,
        required: false,
      },
      datailDisabled: {
        type: Boolean,
        default: false,
      },
      index: {
        type: Number,
        default: null,
      },
          isFk: {
              type: Boolean,
              default: false,
          }
    },
    data() {
      return {
        loading: false,
        basicForm: {
          gsdaId: '',
          isFk: '',
          isSk: '',
        },
        rules: {
          gsdaId: [ { required: true, message: '请选择名称!', trigger: ['blur', 'change'] } ],
          isFk: [ { required: true, message: '请选择是否为付款单位!', trigger: ['blur', 'change'] } ],
          isSk: [ { required: true, message: '请选择是否为收款单位!', trigger: ['blur', 'change'] } ],
                  psnName: [ { required: true, message: '请输入我方经办人!', trigger: ['blur'] } ],
                  psnMobile: [
                      { required: true, message: '请输入联系方式!' },
                      { pattern: /(^1\d{10}$|^(0\d{2,3}-?|\(0\d{2,3}\))?[1-9]\d{4,7}(-\d{1,8})?$)|(^\/$)/, message: '请输入正确的联系方式!', trigger: ['blur', 'change'] }
                  ]
        },
      }
    },
    created() {},
    methods: {
      reset() {
        this.$refs.form.resetFields()
      },
      async onSubmit() {
        await this.$refs.form.validate()
              if(this.loading) return
              this.loading = true
        if (!this.index) {
          this.$emit('submit', [{
            id: parseInt(Math.random() * 1000000000000),
            ...this.basicForm,
          }, this.index])
        } else {
          this.$emit('submit', [this.basicForm, this.index])
        }
      },
      onClose() {
              this.loading = false
        this.$emit('close')
      },
    },
    watch: {
          isFk: {
              handler(val) {
                if(val){
                      this.$set(this.rules,'isFk',[{ required: true, message: '请选择是否为付款单位!' }])
                      this.$delete(this.rules,'isSk')
                  } else {
                      this.$set(this.rules,'isSk',[{ required: true, message: '请选择是否为收款单位!' }])
                      this.$delete(this.rules,'isFk')
                  }
              },
              immediate: true,
          }
    },
  }
  </script>
  
  <style scoped></style>
  